const BaseService=require("./baseService");

class AdminInfoService extends BaseService{
    constructor(){
        super(...arguments);
        this.tableName="admininfo";
    }

    async getListByPage({adminid,realname,pageIndex}={}){
        pageIndex=pageIndex||1;
        let strWhere="";
        if(adminid){
            strWhere+=" and adminid like '%"+adminid+"%'";
        }
        if(realname){
            strWhere+=" and realname like '%"+realname+"%'";
        }
        let strSql=`select * from ${this.tableName} where isDel=false ${strWhere} limit ?,? `;
        let countSql=this.createCountSql(strWhere);
        let result= await this.app.mysql.query(strSql+";"+countSql,[(pageIndex-1)*this.pageSize,this.pageSize]);
        return result;
    }

    async addAdminInfo({adminid,adminpwd,realname,admintel}){
        let result = await this.app.mysql.insert(this.tableName,{adminid,adminpwd,realname,admintel});
        return result.affectedRows>0?true:false;
    }

    /**
     * 
     * @param {string} adminid 账号
     * @returns {boolean} true为存在，false为不存在
     */
    async checkAdminId(adminid){
        let result =await this.app.mysql.get(this.tableName,{adminid});
        if(result){
            return true;
        }
        else{
            return false;
        }
    }
}

module.exports=AdminInfoService;